import React from 'react';
import { CopilotKit } from '@copilotkit/react-core';
import { MamisCopilotConfig } from '../types/config';
import { ShadowDOMManager } from '../isolation/ShadowDOMManager';
import CopilotPopupWrapper from './CopilotPopupWrapper';

interface CopilotKitWrapperProps {
  config: MamisCopilotConfig;
  shadowManager?: ShadowDOMManager;
  onClose?: () => void;
  onMessage?: (message: unknown) => void;
  onPageAction?: (action: string, target: string, result: unknown) => void;
  onError?: (error: Error) => void;
}

/**
 * CopilotKit包装器组件
 * 提供CopilotKit的基础配置和上下文
 */
export const CopilotKitWrapper: React.FC<CopilotKitWrapperProps> = (props) => {
  const {
    config: { runtimeUrl, publicApiKey },
  } = props;

  return (
    <CopilotKit runtimeUrl={runtimeUrl} publicApiKey={publicApiKey}>
      <CopilotPopupWrapper {...props} />
    </CopilotKit>
  );
};

export default CopilotKitWrapper;
